import { createRouter, createWebHistory, createWebHashHistory } from "vue-router";

const CommonRoutes = [
    {
        path: "/",
        name: "home",
        component: () => import("@/pages/home/index.vue"),
        meta: {
            name: "首页",
        },
    },
    {
        path: "/mobileHome",
        name: "MobileHome",
        component: () => import("@/pages/mobileHome/index.vue"),
        meta: {
            name: "首页",
        },
    },
];

const routes = [...CommonRoutes];

const router = createRouter({
    history: createWebHashHistory(),
    routes,
});

router.beforeEach((to, from, next) => {
    console.log(to, from)
    // next({ path: '/login' })
    let width = window.innerWidth
    if (to.fullPath == '/') {
        if (width > 800) {
            next();
        } else {
            router.push('/mobileHome');
        }
    } else {
        if (width > 800) {
            router.push('/')
        } else {
            next();
        }
    }
    // next();
});




router.afterEach((to, from, next) => {
});

export default router;
